package com.hxht.cmp.module;

import com.hxht.cmp.common.Constants;
import com.hxht.cmp.entity.User;
import com.hxht.cmp.service.CaseReviewService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * 庭审回顾与预告直播module控制器
 * @author alice on 2017/7/13 0013.
 * @version 1.0
 * @since 1.0
 */
@Controller
@RequestMapping("more")
public class MoreCaseModule {

    @Autowired
    private CaseReviewService caseReviewService;

    @RequestMapping(value = "/more_notice", method = RequestMethod.GET)
    public ModelAndView moreNotice(String courtUid,String day,String search) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        if (ObjectUtils.isEmpty(courtUid)) {
            User user = (User) session.getAttribute("user");
            courtUid = user.getCourtUid();
        }
        Map<String, Object> selectJudgeAndSecretary = caseReviewService.selectJudgeAndSecretary(courtUid);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("judgeList",selectJudgeAndSecretary.get("judgeList"));
        modelAndView.addObject("secretaryList",selectJudgeAndSecretary.get("secretaryList"));
        modelAndView.addObject("courtroomList", Constants.COURTROOM_LIST);
        modelAndView.addObject("caseTypeList",caseReviewService.getAllCaseType());
        modelAndView.setViewName("more/more_notice");
        return modelAndView;
    }

    @RequestMapping(value = "/more_review", method = RequestMethod.GET)
    public ModelAndView moreReview(String courtUid,String search) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        if (ObjectUtils.isEmpty(courtUid)) {
            User user = (User) session.getAttribute("user");
            courtUid = user.getCourtUid();
        }
        ModelAndView modelAndView = new ModelAndView();
//        Map<String, Object> selectJudgeAndSecretary = caseReviewService.selectJudgeAndSecretary(courtUid);
//        modelAndView.addObject("judgeList",selectJudgeAndSecretary.get("judgeList"));
//        modelAndView.addObject("secretaryList",selectJudgeAndSecretary.get("secretaryList"));
        modelAndView.addObject("courtroomList", Constants.COURTROOM_LIST);
        modelAndView.addObject("caseTypeList",caseReviewService.getAllCaseType());
        modelAndView.setViewName("more/more_review");
        return modelAndView;
    }

    @RequestMapping(value = "/on_time_show", method = RequestMethod.GET)
    public ModelAndView onTimeShow(String courtUid) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        if (ObjectUtils.isEmpty(courtUid)) {
            User user = (User) session.getAttribute("user");
            courtUid = user.getCourtUid();
        }
//        Map<String, Object> selectJudgeAndSecretary = caseReviewService.selectJudgeAndSecretary(courtUid);
        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.addObject("judgeList",selectJudgeAndSecretary.get("judgeList"));
//        modelAndView.addObject("secretaryList",selectJudgeAndSecretary.get("secretaryList"));
        modelAndView.addObject("courtroomList", Constants.COURTROOM_LIST);
        modelAndView.addObject("caseTypeList",caseReviewService.getAllCaseType());
        modelAndView.addObject("onTimeTypeList",caseReviewService.getAllOnTimeType());
        modelAndView.setViewName("more/court_on_time_show");
        return modelAndView;
    }
}
